package persistency.writer;

import java.util.Collection;
import java.util.Iterator;

public abstract class IntersectionWriter extends Writer {
	
	/**
	 * Creates a new IntersectionWriter Object
	 * @param filePath The file that will be used to store the data
	 * @param header The header that will be written in data file
	 */
	public IntersectionWriter(String filePath, String header) {
		super(filePath, header);
	}
	
	/**
	 * Writes a parent child relation in an intersection table
	 * @param parent The parent primary key
	 * @param child The child primary key
	 */
	public void write(Object parent, Object child){
		write(parent + "\t" + child + "\n");
		
	}
	
	/**
	 * Writes a collection of child keys for a parent in an intersection text file
	 * @param parentKey The parent Primary key
	 * @param writables The collection of child data
	 */
	public void write(Object parentKey, Collection<? extends Writable> writables){
		Iterator<? extends Writable> writablesIterator = writables.iterator();
		while (writablesIterator.hasNext()) {
			write(parentKey, writablesIterator.next().getPrimaryKey());
		}
	}
}